from django.shortcuts import render,redirect

# Create your views here.
from activity.models import Activity,School

from django.views import View



def delete(request,id):
    print('1111111111111',id)

    School.objects.get(id=id).delete()

    return redirect('/activity/info/')


class AddView(View):
    def get(self,request):
        school_data=School.objects.all()
        return render(request,'add.html',locals())
    def post(self,reqest):
        aa=reqest.POST
        print(aa)
        Activity.objects.create(
            number=reqest.POST.get('number'),
            title=reqest.POST.get('title'),
            school_id=3


        )
        School.objects.create(
            name='海淀',
            start_time=reqest.POST.get('start_time'),
            end_time=reqest.POST.get('end_time')
        )


        return redirect('/activity/info/')

import time
time.strftime()
class InfoView(View):
    def get(self,request):
        school_data=Activity.objects.all()
        print('=========',school_data.values('school__start_time'))
        start_time = School.objects.values('start_time')
        end_time = School.objects.values('end_time')

        print(start_time)
        for i in school_data:
            i.start_time=start_time[1]['start_time'].strftime("%Y-")
            i.end_time=end_time[1]['end_time'].strftime()
        print(start_time,end_time)


        return render(request,'info.html',locals())
    def post(self,reuqest):
        pass


